package com.greyu.ysj.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.greyu.ysj.entity.CbtConstant;
import com.greyu.ysj.entity.CbtStarLevel;
import com.greyu.ysj.entity.CbtStarLevelExample;
import com.greyu.ysj.mapper.CbtStarLevelMapper;
import com.greyu.ysj.service.CbtStarLevelService;
@Service
public class CbtStarLevelServiceImpl implements CbtStarLevelService {
	@Autowired 
	private CbtStarLevelMapper cbtStarLevelMapper;
	@Override
	public CbtStarLevel selectUserStarLevel(double asset, int invited_mount) {
		// TODO Auto-generated method stub
		List<CbtStarLevel> lists = this.cbtStarLevelMapper.selectByExample(new CbtStarLevelExample());
		CbtStarLevel Ret = lists.get(0);
		for (CbtStarLevel cbtStarLevel : lists) {
			if (((asset >= cbtStarLevel.getMinAsset() && asset <=cbtStarLevel.getMaxAsset()) 
				|| asset >= cbtStarLevel.getMaxAsset() )
				&& invited_mount >= cbtStarLevel.getInvitedAmount()) 
			{
				Ret = cbtStarLevel;
			}
		}
		return Ret;
	}
	@Override
	public CbtStarLevel selectUserStarLevelByStar(int star) {
		// TODO Auto-generated method stub
		CbtStarLevelExample cbtStarLevelExample = new CbtStarLevelExample();
		CbtStarLevelExample.Criteria criteria = cbtStarLevelExample.createCriteria();
		criteria.andStarEqualTo(star);
		List<CbtStarLevel> cbtStarLevels = this.cbtStarLevelMapper.selectByExample(cbtStarLevelExample);
		CbtStarLevel cbtStarLevel;
        try {
        	cbtStarLevel = cbtStarLevels.get(0);
        } catch (Exception e) {
            return null;
        }
        return cbtStarLevel;
	}

}
